//
//  NavigationView.swift
//  SwiftNews
//
//  Created by admin on 15/10/23.
//  Copyright © 2015年 admin. All rights reserved.
//

import UIKit
 typealias returnLeftButtonClicked = ()-> () //或者 () -> Void


class NavigationView: UIView {

    
    
    var returnButton:UIButton!
    var headImageView:UIImageView!
    var rightButton:UIButton!
    var textLabel:UILabel!
    var returnLeftButtonClicked:(Void) ->Void = {}
    var returnRightButtonClicked:(Void) ->Void = {}
   
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addView();
    }

    func addView (){
    
        returnButton = UIButton(type: UIButtonType.Custom )
        returnButton.frame=CGRectMake(0, 0,self.frame.size.height , self.frame.size.height)
        returnButton.setTitle("返回", forState: UIControlState.Normal)
        returnButton .addTarget(self, action: "returnButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        returnButton.imageEdgeInsets = UIEdgeInsetsMake(20, 20, 10,10)
        
        self.addSubview(returnButton)
    
        
        rightButton = UIButton(type: UIButtonType.Custom )
        rightButton.frame=CGRectMake(self.frame.size.width-70, 0,60 , 60)
        rightButton.setTitle("返回", forState: UIControlState.Normal)
        rightButton .addTarget(self, action: "rightButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        rightButton.imageEdgeInsets = UIEdgeInsetsMake(20, 20, 10,10)
        self.addSubview(rightButton)
        
        
        
        headImageView = UIImageView ();
        self.addSubview(headImageView)
        
        
        textLabel = UILabel()
        textLabel.textAlignment=NSTextAlignment.Center
        self.addSubview(textLabel)
        
        
        
    }
    
    func setHeadImageView(imagewidth:CGFloat,imageName:NSString){
    
        let lastWidth = self.frame.size.width - imagewidth - returnButton.frame.size.width - rightButton.frame.size.width
        
        headImageView.frame=CGRectMake(lastWidth/2, 20, imagewidth, self.frame.size.height-30)
        
        headImageView.image = UIImage (named:imageName as String)
    
    
    }
    
    
    func setTextLabelView(labelwidth:CGFloat,labelText:NSString){
        
        let lastWidth = self.frame.size.width - labelwidth - returnButton.frame.size.width - rightButton.frame.size.width
        
        textLabel.frame=CGRectMake(lastWidth/2, 20, labelwidth, self.frame.size.height-30)
        textLabel.text = labelText as String
     
        
    }

    
    //按钮点击事件
    
    func returnButtonClicked(returnButtonClicked:UIButton){
    
        self.returnLeftButtonClicked()
        
        
    }
    
    func rightButtonClicked (rightButtonClicked:UIButton ){
    
        self.returnRightButtonClicked()
    }
    
    
    //获取view对位置的款
    func get_view_width (view:UIView) -> CGFloat
    {
        return view.frame.size.width
        
    }
    
    func get_view_height (view:UIView) -> CGFloat
    {
        return view.frame.size.height
        
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
